package com.yj.provider.response;

import com.yj.provider.exception.BusException;
import lombok.Data;

import javax.xml.transform.Result;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

/**
 * 定义统一的返回值
 */

@Data
public class ResultResponse {

    private int code;
    private String message;
    private Map<String,Object> data = new HashMap<>();

    private ResultResponse(){
    }

//    public ResultResponse(int code,String message){
//        this.code = code;
//        this.message = message;
//    }

    public static ResultResponse success(){
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.code = 20000;
        resultResponse.message = "success";
        return resultResponse;
    }

    public static ResultResponse failure(){
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.code = 50000;
        resultResponse.message = "failure";
        return resultResponse;
    }

    public static  ResultResponse failure(BusException busException){
        ResultResponse resultResponse = new ResultResponse();
        resultResponse.code = busException.getCode();
        resultResponse.message = busException.getMessage();
        return resultResponse;
    }

    public ResultResponse code(int code){
        this.code = code;
        return this;
    }
    public ResultResponse message(String message){
        this.message = message;
        return this;
    }
    public ResultResponse data(String key,Object value){
        this.data.put(key,value);
        return this;
    }
    public ResultResponse data(Map<String,Object>map){
        this.data = map;
        return this;
    }

}
